package com.chanyachting.emall.action.index;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.chanyachting.emall.domain.Applicationleter;
import com.chanyachting.emall.form.JobSearchForm;
import com.chanyachting.emall.service.ApplicationLeterService;
import com.chanyachting.emall.serviceImpl.ApplicationLeterServiceImpl;

public class QueryAppJob extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		//主页页面记录数
		int COMMON_PAGE_SIZE = 6;
		
		ApplicationLeterService alService = new ApplicationLeterServiceImpl();
		List<Applicationleter> alList = null;
		JobSearchForm tForm = (JobSearchForm)form;
		int currentPage = tForm.getCurrentPage();
		int pageSize = COMMON_PAGE_SIZE;
		
		int pageCount = alService.getApplicationleterCount("02")/pageSize;
		
		if (pageCount%pageSize > 0) {
			pageCount = pageCount + 1;
		}
		
		if (currentPage < 1) {
			currentPage = 1;
		} else if (currentPage > pageCount) {
			return mapping.findForward("error");
		}
		
		alList = alService.getAllApplicationleterByPageBreak(currentPage - 1, pageSize);

		tForm.setJobList(alList);
		return mapping.findForward("appJobs");
	}
}
